const stadiumService = require('../service/stadium.service')
const { STADIUM_ID_REQUIRED, GET_STADIUM_DETAIL_EXCEPTION} = require('../error/errorType')

const verifyStadium = async (ctx, next) => {
    const { id: stadiumId } = ctx.request.params
    if (!stadiumId) {
        return ctx.app.emit('error', new Error(STADIUM_ID_REQUIRED), ctx)
    }
    ctx.stadiumId = stadiumId
    await next()
}

const verifyKeyword = async (ctx, next) => {
    const { keyword } = ctx.request.query
    if (keyword && keyword.trim() != '') {
        ctx.word = keyword.trim()
    }
    await next()
}

// const verifyCode = async (ctx, next) => {
//     const { id: stadiumId } = ctx.request.query
//     if (!stadiumId) {
//         return ctx.app.emit('error', new Error(STADIUM_ID_REQUIRED), ctx)
//     }
//     let [ stadium ] = await stadiumService.getById(stadiumId)
//     if (!stadium) {
//         return ctx.app.emit('error', new Error(GET_STADIUM_DETAIL_EXCEPTION), ctx)
//     }
//     ctx.stadiumId = stadiumId
//     await next()
// }

module.exports = {
    verifyStadium,
    verifyKeyword,
    // verifyCode,
}